﻿<r:RibbonWindow 
    x:Class="TreeBuilder.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:tb="clr-namespace:TreeBuilder"
    xmlns:r="clr-namespace:Fluent;assembly=Fluent"
    xmlns:f="clr-namespace:FontDialogSample;assembly=FontDialogSample"
    Height="450" Width="525"
    WindowStyle="SingleBorderWindow"
    Icon="/TreeBuilder;component/Icons/tree-icon_32.png"
    Closing="RibbonWindow_Closing"
    WindowState="Maximized"
    Title="TreeBuilder">
    <r:RibbonWindow.Resources>
        <!--Commands-->
        <Style x:Key="ButtonPathStyle" TargetType="{x:Type Path}" >
            <Setter Property="Stroke" Value="#FF333333"/>
            <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=Button, AncestorLevel=1}, Path=Foreground}"/>
        </Style>
        <!--Tabs-->
        <Style x:Key="CloseableTabItemButtonStyle" TargetType="{x:Type Button}">
            <Style.Resources>
                <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#F3F3F3" Offset="0"/>
                    <GradientStop Color="#EBEBEB" Offset="0.5"/>
                    <GradientStop Color="#DDDDDD" Offset="0.5"/>
                    <GradientStop Color="#CDCDCD" Offset="1"/>
                </LinearGradientBrush>
                <LinearGradientBrush x:Key="ButtonPressedBackground" EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#FFE0E0E2" Offset="0"/>
                    <GradientStop Color="#FFF8F8F8" Offset="1"/>
                </LinearGradientBrush>
                <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF969696"/>
            </Style.Resources>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="#FF969696"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="4"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Border SnapsToDevicePixels="true" x:Name="Chrome" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" Opacity="0" />
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" TargetName="Chrome" Value="0"/>
                                <Setter Property="Background" TargetName="Chrome" Value="{DynamicResource ButtonOverBackground}" />
                                <Setter Property="Foreground" Value="Red"/>
                                <Setter Property="Padding" Value="2"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Opacity" TargetName="Chrome" Value="1"/>
                                <Setter Property="Background" TargetName="Chrome" Value="{DynamicResource ButtonPressedBackground}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Key="TabItemTemplate">
            <DockPanel Name="HeaderGrid">
                <TextBlock Name="HeaderText" Text="{Binding DataContext.DisplayName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}" />
                <Button 
                    Name="CloseButton" 
                    Command="Close" 
                    CommandParameter="{Binding DataContext}" 
                    Grid.Column="2"
                    Style="{DynamicResource CloseableTabItemButtonStyle}"
                    Height="16" Width="16">
                    <Path x:Name="Path" Stretch="Fill" StrokeThickness="0.5"
                          Style="{StaticResource ButtonPathStyle}"
                          Data="F1 M 2.28484e-007,1.33331L 1.33333,0L 4.00001,2.66669L 6.66667,6.10352e-005L 8,1.33331L 5.33334,4L 8,6.66669L 6.66667,8L 4,5.33331L 1.33333,8L 1.086e-007,6.66669L 2.66667,4L 2.28484e-007,1.33331 Z" 
                          HorizontalAlignment="Stretch" 
                          VerticalAlignment="Stretch"/>
                </Button>
            </DockPanel>
        </DataTemplate>
        <Style x:Key="TabItemStyle" TargetType="TabItem">
            <Setter Property="HeaderTemplate" Value="{StaticResource TabItemTemplate}" />
        </Style>
    </r:RibbonWindow.Resources>
    <r:RibbonWindow.CommandBindings>
        <CommandBinding Command="Open" Executed="OpenCommand_Executed"/>
        <CommandBinding Command="New" Executed="NewCommand_Executed"/>
        <CommandBinding Command="Close" Executed="CloseCommand_Executed"/>
        <CommandBinding Command="Save" Executed="SaveCommand_Executed"/>
        <CommandBinding Command="SaveAs" Executed="SaveAsCommand_Executed"/>
        <CommandBinding Command="Print" Executed="PrintCommand_Executed"/>
        <CommandBinding Command="tb:Commands.Exit" Executed="ExitCommand_Executed"/>
        <CommandBinding Command="tb:Commands.Options" Executed="OptionsCommandExecuted"/>
        <CommandBinding Command="Help" Executed="HelpCommand_Executed"/>
        <CommandBinding Command="tb:Commands.About" Executed="AboutCommand_Executed"/>
        <CommandBinding Command="tb:Commands.SaveAll" Executed="SaveAll_Executed"/>
        <CommandBinding Command="tb:Commands.SetFont" Executed="SetFont_Executed" CanExecute="SetFont_CanExecute"/>
    </r:RibbonWindow.CommandBindings>
    <r:RibbonWindow.InputBindings>
        <KeyBinding Gesture="CTRL+N" Command="New"/>
        <KeyBinding Gesture="CTRL+O" Command="Open"/>
        <KeyBinding Gesture="CTRL+S" Command="Save" CommandParameter="tree"/>
        <KeyBinding Gesture="CTRL+SHIFT+S" Command="tb:Commands.SaveAll"/>
        <KeyBinding Gesture="CTRL+P" Command="Print"/>
    </r:RibbonWindow.InputBindings>
    <Grid Name="MainGrid" AllowDrop="False">
        <Grid.RowDefinitions>
            <RowDefinition Height="{Binding ElementName=MainRibbon,Path=Height}"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="27"/>
        </Grid.RowDefinitions>
        <r:Ribbon x:Name="MainRibbon">
            <r:Ribbon.Resources>
                <Style TargetType="r:RibbonContextualTabGroup">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </Style>
            </r:Ribbon.Resources>
            <r:Ribbon.Menu>
                <r:ApplicationMenu>
                    <r:MenuItem Header="New" SizeDefinition="Large" ToolTip="New (Ctrl+N)" Command="New" Icon="/Icons/NewFile_32.png"/>
                    <r:MenuItem  Header="Open" ToolTip="Open (Ctrl+O)" Command="Open" Icon="/Icons/open_32.png"/>
                    <r:MenuItem 
                        Header="Save" 
                        Command="Save" 
                        CommandParameter="tree"
                        ToolTip="Save (Ctrl+S)"
                        Icon="/Icons/save_32.png"/>
                    <r:MenuItem 
                        Header="Save all" 
                        Command="tb:Commands.SaveAll" 
                        ToolTip="Save all (Ctrl+Shift+S)"
                        Icon="/Icons/saveall_32.png"/>
                    <r:MenuItem Header="Save as..." Command="SaveAs" Icon="/Icons/SaveAs_32.png">
                        <r:MenuItem 
                            Header="*.tree file (recommended)"
                            Description="Choose if you want to open the tree again"
                            Icon="/Icons/tree-icon_32.png"
                            Command="SaveAs" CommandParameter="tree"
                            />
                        <r:GroupSeparatorMenuItem/>
                        <r:MenuItem 
                            Header="*.png image (recommended)"
                            Icon="/Icons/png_32.png"
                            Description="Lossless compressed image file"
                            Command="Save" CommandParameter="png"
                            />
                        <r:MenuItem 
                            Header="*.jpeg image"
                            Icon="/Icons/jpeg_32.png"
                            Description="Lossy compressed image file"
                            Command="Save" CommandParameter="jpeg"
                            />
                        <r:MenuItem 
                            Header="*.bmp image"
                            Icon="/Icons/bmp_32.png"
                            Description="Raw bitmap file (without compression)"
                            Command="Save" CommandParameter="bmp"
                            />
                    </r:MenuItem>
                    <r:GroupSeparatorMenuItem/>
                    <r:MenuItem Header="Print" ToolTip="Print (Ctrl+P)" Command="Print" Icon="/Icons/print_32.png"/>
                    <r:MenuItem Header="Close" Command="Close" Icon="/Icons/Close_32.png"
                                                      CommandParameter="current"
                                                      />
                    <r:GroupSeparatorMenuItem/>
                    <r:MenuItem Header="Help" Command="Help" Icon="/Icons/help_32.png">
                        <r:MenuItem Header="Tutorial..." Description="Open interactive tutorial"  Command="Help" Icon="/Icons/help_32.png"/>
                        <r:MenuItem Header="About..." Description=""  Command="tb:Commands.About"/>
                    </r:MenuItem>
                    <r:MenuItem Header="Options..."
                                Command="tb:Commands.Options" Icon="/Icons/Options_32.png"/>
                    <r:MenuItem Header="Exit"
                                Command="tb:Commands.Exit" Icon="/Icons/Exit.png"/>
                </r:ApplicationMenu>
            </r:Ribbon.Menu>
            <r:Ribbon.ContextualGroups>
                <r:RibbonContextualTabGroup Name="NodeContextualGroup" Header="Nodes"
                                            Background="Green" BorderBrush="{Binding RelativeSource={RelativeSource Self},Path=Background}"/>
                <r:RibbonContextualTabGroup Name="BinderContextualGroup" Header="Binders"
                                            Background="DodgerBlue" BorderBrush="{Binding RelativeSource={RelativeSource Self}, Path=Background}"/>
            </r:Ribbon.ContextualGroups>
            <r:RibbonTabItem Header="Edit">
                <r:RibbonGroupBox Header="Actions">
                    <r:Button Command="Undo" Icon="/TreeBuilder;component/Icons/undo.png"
                                    LargeIcon="/TreeBuilder;component/Icons/undo.png" Header="Undo" ToolTip="Undo (Ctrl+Z)"/>
                    <r:Button Command="Redo" Icon="/TreeBuilder;component/Icons/redo.png"
                                    LargeIcon="/TreeBuilder;component/Icons/redo.png" Header="Redo" ToolTip="Redo (Ctrl+Y)"/>
                </r:RibbonGroupBox>
                <r:RibbonGroupBox Header="Clipboard">
                    <r:Button Command="SelectAll" Header="Select all" LargeIcon="/TreeBuilder;component/Icons/select_all.png" ToolTip="Select all (Ctrl+A)"/>
                    <r:Button Command="Copy" Header="Copy" LargeIcon="/TreeBuilder;component/Icons/copy.png" ToolTip="Copy (Ctrl+C)"/>
                    <r:Button Command="Paste" Header="Paste" LargeIcon="/TreeBuilder;component/Icons/paste.png" ToolTip="Paste (Ctrl+V)"/>
                </r:RibbonGroupBox>
                
            </r:RibbonTabItem>
            <r:RibbonTabItem Name="NodeTab" Group="{Binding ElementName=NodeContextualGroup}" Header="Text">
                <r:RibbonGroupBox Header="Node">
                    <r:InRibbonGallery MinItemsInRow="3" ResizeMode="Both" MaxItemsInRow="5" Name="FontGallery" Selectable="False">
                        <r:InRibbonGallery.ItemTemplate>
                            <DataTemplate DataType="f:Font">
                                <r:GalleryItem Command="tb:Commands.SetFont" CommandParameter="{Binding}">
                                    <Border Width="50" Height="25" Margin="0">
                                        <Border.ToolTip>
                                            <ToolTip Content="{Binding}" />
                                        </Border.ToolTip>
                                        <TextBlock Text="Example"
                                                   VerticalAlignment="Center"
                                                   HorizontalAlignment="Left"
                                                   FontFamily="{Binding FontFamily}" 
                                                   Foreground="{Binding Foreground}" 
                                                   FontSize="{Binding FontSize}"
                                                   FontStretch="{Binding FontStretch}"
                                                   FontStyle="{Binding FontStyle}"
                                                   FontWeight="{Binding FontWeight}"
                                                   TextDecorations="{Binding TextDecorations}"
                                                   />
                                    </Border>
                                </r:GalleryItem>
                            </DataTemplate>
                        </r:InRibbonGallery.ItemTemplate>
                        <r:InRibbonGallery.Items>
                            <f:Font FontFamily="Arial" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Normal" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Arial" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Italic" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Colibri" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Normal" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Colibri" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Italic" FontWeight="Normal" TextDecorations=""/>                            
                            <f:Font FontFamily="Times New Roman" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Normal" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Times New Roman" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Italic" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Courier New" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Normal" FontWeight="Normal" TextDecorations=""/>
                            <f:Font FontFamily="Courier New" Foreground="Black" FontSize="14" FontStretch="Normal" FontStyle="Italic" FontWeight="Normal" TextDecorations=""/>
                        </r:InRibbonGallery.Items>
                    </r:InRibbonGallery>
                </r:RibbonGroupBox>
            </r:RibbonTabItem>
            <r:RibbonTabItem Name="BindersTab" Header="Lines" Group="{Binding ElementName=BinderContextualGroup}">
                <r:RibbonGroupBox>
                    <TextBlock>Color:</TextBlock>
                </r:RibbonGroupBox>
            </r:RibbonTabItem>
        </r:Ribbon>
        <TabControl
            Grid.Row="1"
            Grid.RowSpan="2"
            Name="TabControl"
            ItemContainerStyle="{StaticResource TabItemStyle}"
            ItemsSource="{Binding}">
        </TabControl>
        <Border Opacity="0"
                Name="UpdateNotificationBorder"
                Visibility="Collapsed"
                Grid.Row="2"
                Background="{x:Static SystemColors.InfoBrush}">
            <Grid>
                <TextBlock HorizontalAlignment="Center"
                           VerticalAlignment="Center">A newer version of TreeBuilder exists.
                <Hyperlink NavigateUri="http://treebuilder.ru/Home/Download"
                           RequestNavigate="UpdateUri_RequestNavigate">Go to download page...</Hyperlink>
                </TextBlock>
                <Button HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Background="{x:Static SystemColors.InfoTextBrush}"
                        Style="{DynamicResource CloseableTabItemButtonStyle}"
                        Height="16"
                        Width="16"
                        Margin="5,0,10,0"
                        Click="CloseUpdateInfo_Click">
                    <Path Stretch="Fill"
                          StrokeThickness="0.5"
                          Style="{StaticResource ButtonPathStyle}"
                          Data="F1 M 2.28484e-007,1.33331L 1.33333,0L 4.00001,2.66669L 6.66667,6.10352e-005L 8,1.33331L 5.33334,4L 8,6.66669L 6.66667,8L 4,5.33331L 1.33333,8L 1.086e-007,6.66669L 2.66667,4L 2.28484e-007,1.33331 Z"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch" />
                </Button>
            </Grid>
        </Border>
        <Border Opacity="0"
                Name="FirstTimeTipsBorder"
                Visibility="Collapsed"
                Grid.Row="2"
                Background="{x:Static SystemColors.InfoBrush}">
            <Grid>
                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
                    Tip: double click on the canvas -> new node; click on the node and draw lines.
                </TextBlock>
                <Button HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Background="{x:Static SystemColors.InfoTextBrush}"
                        Style="{DynamicResource CloseableTabItemButtonStyle}"
                        Height="16"
                        Width="16"
                        Margin="5,0,10,0"
                        Click="CloseFirstTimeTips_Click">
                    <Path Stretch="Fill"
                          StrokeThickness="0.5"
                          Style="{StaticResource ButtonPathStyle}"
                          Data="F1 M 2.28484e-007,1.33331L 1.33333,0L 4.00001,2.66669L 6.66667,6.10352e-005L 8,1.33331L 5.33334,4L 8,6.66669L 6.66667,8L 4,5.33331L 1.33333,8L 1.086e-007,6.66669L 2.66667,4L 2.28484e-007,1.33331 Z"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch" />
                </Button>
            </Grid>
        </Border>
    </Grid>
</r:RibbonWindow>
